package cn.stronglink.asset.terminal.unicom.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSON;

import cn.stronglink.asset.model.PresetDetail;
import cn.stronglink.asset.model.PutOnDetail;
import cn.stronglink.asset.model.TRoom;
import cn.stronglink.asset.model.User;
import cn.stronglink.asset.module.assetmanage.itasset.service.ItassetService;
import cn.stronglink.asset.module.sys.user.service.UserService;
import cn.stronglink.asset.terminal.unicom.param.DoCheckParam;
import cn.stronglink.asset.terminal.unicom.service.ApiService;
import cn.stronglink.suite.core.base.AbstractController;

@Controller
@RequestMapping(value = "terminal")
public class TerminalAPIController extends AbstractController {

	@Autowired
	private UserService userService;
	@Autowired
	private ItassetService itassetService;
	@Autowired
	private ApiService apiService;

	
	/**
	 * 手持用户登录
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param params
	 * @return
	 */
	@RequestMapping(value = "getUsers")
	public ResponseEntity<ModelMap> getUsers(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response) {
		List<User> user = userService.qryAllUser();		
		return setSuccessModelMap(modelMap, user);
		
	}
	
	/**
	 * 手持端  查询需要验收的列表  
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param params
	 * @return
	 */
	@RequestMapping(value = "qryCheckList")
	public ResponseEntity<ModelMap> qryCheckBeforeList(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response) {	
		List<PresetDetail> data = apiService.qryTerminalCheckList();
		System.out.println(JSON.toJSON(data)+"*************验收单********** ");
		return setSuccessModelMap(modelMap, data);
	}	
	
	/**
	 * 手持 获取上架单 
	 * @param modelMap
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "getRackList")
	public ResponseEntity<ModelMap> getRackList(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response) {
		List<TRoom> data = itassetService.getRackListByUserId();
		System.out.println(JSON.toJSON(data)+"*************机房和机柜************* ");
		return setSuccessModelMap(modelMap, data);
	}	
	
	/**
	 * 手持 获取上架单 
	 * @param modelMap
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "getPutUpList")
	public ResponseEntity<ModelMap> getPutUpList(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response) {
		List<PutOnDetail> data = apiService.getTerminalPutUpList();	
		System.out.println(JSON.toJSON(data)+"&&&&&&&&&&&上架单&&&&&&&&&&&& ");
		return setSuccessModelMap(modelMap, data);
	}	
	
	/**
	 * 手持 到货验收
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param asset
	 * @return
	 */
	@RequestMapping(value = "doCheckTerminal")
	public ResponseEntity<ModelMap> doCheckTerminal(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody List<DoCheckParam> assetList) {
		//联通业务调用方法
		System.out.println(JSON.toJSON(assetList)+"************验收数据数据**************");
		String msg=null;
		try {
			msg = apiService.checkTerminal(assetList);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//川庆业务调用方法
		//apiService.cqCheckTerminal(assetList);
		return setSuccessModelMap(modelMap, msg);
	}	
	
	/**
	 * 手持 上架
	 * @param modelMap
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "doPutOn")
	public ResponseEntity<ModelMap> doPutOn(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody List<PutOnDetail> putOnList) {
		System.out.println(JSON.toJSON(putOnList)+"************上架数据数据****************");
		//联通业务调用方法
		String msg=null;
		try {
			msg = apiService.doPutOn(putOnList);
		} catch (Exception e) {
			e.printStackTrace();
		}
		//川庆业务调用方法
		//apiService.cqDoPutOn(putOnList);
		
		return setSuccessModelMap(modelMap, msg);
	}	


}
